package demo.IOInputOutput;

import java.io.*;
import java.util.Arrays;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/12-08-12-14:50
 * @Description：demo.IOInputOutput   包装流   数据流  DateOutputStream DateInputStream
 */
public class pagee_Stream {
    public static void main(String[] args) {
        //数据来源
        DataInputStream dis = null;
        //声明创建流
        //写到字节数组  包装字节数组
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(out);



        try {
            //使用流
            dos.writeLong(1000l);
            dos.writeChars("中国");
            byte[] b = out.toByteArray();
            System.out.println(Arrays.toString(b));
            //System.out.println(Arrays.toString(out.toByteArray()));
            //读出数据
            ByteArrayInputStream in = new ByteArrayInputStream(b);
            dis = new DataInputStream(in);
            System.out.println(dis.readLong());
            System.out.println(dis.readChar());

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                //只需关闭包装流，节点流out会自动关闭
                dos.close();
                dis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
